package com.kdtech.analyse.Bbs;
import com.kdtech.crawler.at.UrlArgumentTop;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.DoMainUtils;
import com.kdtech.utils.HtmlCleaner;
import com.kdtech.utils.NumberUtils;
import com.kdtech.utils.StringUtils;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.crawler.CrawlHTML;

import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.analyse.AnalyseNews;

/**
 * 上饶房地产论坛 网站解析
 * @author Chase
 *
 */
public class _0793fdcBbsAnalyse implements AnalyseNews {
	//http://bbs.0793fdc.com/viewthread.php?tid=229253&extra=page%3D1
	private static final String[] regex = {
		"http://bbs.0793fdc.com/viewthread.php[?]extra=.*&tid=[0-9]*",
		"http://bbs.0793fdc.com/viewthread.php[?]tid=[0-9]*&extra=.*",
	};


	
	public boolean isDetailPage(String url) {
		for (int i = 0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				return true;
			}
		}
		return false;
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		NewsMeta meta = new NewsMeta();
		if (urlMeta.getHtml() == null) {
		}
		String url = urlMeta.getUrl();
		/*
		 * 网站源码
		 */
		String htmltxt = urlMeta.getHtml();

		if(!isDetailPage(url)){
		}


		String title = null;
		String content = null;
		String author = null;
		Long date = null;
		Document doc = Jsoup.parse(htmltxt);

		/*
		 * 标题
		 */
		title = doc.select("title").text();
		title = StringUtils.substringBefore(title, "-");

		/*
		 * 时间
		 */
		date = DateUtils.matchDate(doc.select("div.authorinfo").text());

		if(StringUtils.isBlank(title) || date == null){
		}

		/*
		 * 内容
		 */
		content = HtmlCleaner.getContentHtml(url, doc.select("div.t_msgfontfix"));

		/*
		 * 作者
		 */
		author = doc.select("a.posterlink").get(0).text();

		/*
		 * 链接
		 */
		meta.setUrl(url);

		/*
		 * 来源
		 */
		meta.setTitle(title);
		meta.setContent(content);
		meta.setAuthor(author);
		meta.setDate(date);



		return meta;
	}

	

	
	public NewsMeta Update(NewsMeta meta) {
		return null;
	}


	
}
